<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<div class="page-header">
	<h1>Backup files:</h1>
</div>

<form:form method="post" commandName="backUpListCommand">
	<div class="scroll">
		<table class="table table-striped table-condensed black">
			<thead>
				<tr>
					<th>Backup File</th>
					<th>Backup Size</th>
					<th>Creation Date</th>
					<th colspan="3"></th>
				</tr>
			</thead>
			<c:forEach var="backUp" items="${backUpListCommand.backUps}"
				varStatus="iterator">
				<tr>
					<td><a
						href=<c:url value='/admin/advanced/backup/download/${backUp.id}'/>>${backUp.fileName}</a>
					</td>
					<td>${backUp.fileSize}</td>
					<td><fmt:formatDate value="${backUp.creationDate}" pattern="dd.MM.yyyy HH:mm:ss"/></td>
					<td>
						<span id="btnDelete" class="badge badge-info pointerCursor"
							onclick="showMessage(${backUp.id}, 'delete');"
							title="Delete backUp file">
							<i class="icon-remove icon-white"></i>
						</span>
					</td>
					<td>
						<c:choose>
							<c:when test="${isBusy}">
								<span id="btnRestore" class="badge"
									  title="Restore from this file">
									<i class="icon-play-circle icon-white"></i>
								</span>
							</c:when>
							<c:otherwise>
								<span id="btnRestore" class="badge badge-info pointerCursor"
									  title="Restore from this file"
									  onclick="showMessage(${backUp.id}, 'restore');">
									<i class="icon-play-circle icon-white"></i>
								</span>
							</c:otherwise>
						</c:choose>
					</td>
					<td>
						<span id="btnCheck" class="badge badge-info pointerCursor"
							  title="Check backUp file"
							  onclick="location.href='<c:url value="/admin/advanced/check/${backUp.id}"/>'">
							<i class="icon-check icon-white"></i>
						</span>
					</td>
				</tr>
			</c:forEach>
		</table>
	</div>

	<div id="myModal" class="modal fade in" style="display: none;">
		<div class="modal-header" style="border-bottom: 0px;">
			<a href="#" class="close" data-dismiss="modal">&times;</a>
			<h3>Confirm</h3>
		</div>
		<div class="modal-body">
			<div>
				<p>
					<strong id="message"></strong>
				</p>
			</div>
		</div>
		<div class="modal-footer">
			<div class="alert-actions">
				<a id="btnNo" class="btn" data-dismiss="modal" href="#">No</a>
				<a id="btnYes" class="btn btn-primary" href="#">Yes</a>
			</div>
		</div>
	</div>

</form:form>

<c:if test="${startFailMsg != null}">
	<div id="startFailDlg" class="modal fade in">
		<div class="modal-header" style="border-bottom: 0px; display: block;">
			<a href="#" class="close">&times;</a>
			<h3>Failed to start process</h3>
		</div>
		<div class="modal-body">
			<div>
				<p>${startFailMsg}</p>
			</div>
		</div>
		<div class="modal-footer">
			<div class="alert-actions">
				<a id="btnNo" class="btn close">OK</a>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		$('#startFailDlg').modal({
			backdrop: true,
			keyboard: true,
			show: true
		});
	</script>
</c:if>

<script type="text/javascript">
	setActiveMainMenuElem('administration');
	$('#menuAdvanced').addClass('active');
	function showMessage(backUpId, cmnd) {
		if (cmnd == "delete") {
			document.getElementById('message').innerHTML = "Do you want to delete this back up?";
			document.getElementById('btnYes').setAttribute('href', '<c:url value="/admin/advanced/backup/remove/' + backUpId +'"/>');
		} else if (cmnd == "restore") {
			document.getElementById('message').innerHTML = "Do you want to restore system?";
			document.getElementById('btnYes').setAttribute('href', '<c:url value="/admin/advanced/restore/'+ backUpId +'"/>');
		} else if (cmnd == "backup") {
			document.getElementById('message').innerHTML = "Do you want to backup?";
			document.getElementById('btnYes').setAttribute('href', '<c:url value="/admin/advanced/backup"/>');
		}
		
		$('#myModal').modal({
			backdrop: true,	
			keyboard: true,
			show: true,
		});
	};
</script>
